<?php

namespace app\admin\model;

use app\common\model\TimeModel;

/**
 * Class RechargeAddress
 * @package app\admin\model
 * User : Orange Tel: 181-3414-1353 QQ:1139552211
 * Date    : 2021/6/11 下午5:11
 */
class RechargeAddress extends TimeModel {

    protected $name = "recharge_address";

    protected $deleteTime = "delete_time";


    /**
     * 获取状态
     * @return string[]
     * User : Orange Tel: 181-3414-1353 QQ:1139552211
     * Date    : 2021/6/11 下午5:11
     */
    public function getStatusList() {
        return ['0' => '禁用', '1' => '启用',];
    }

    /**
     * 获取所有地址类型码
     * @return array
     * User : Orange Tel: 181-3414-1353 QQ:1139552211
     * Date    : 2021/6/11 下午3:54
     */
    public function getAddressTypeInfo() {
        $config = config('addresstype');
        $data   = [];
        $i      = 0;
        foreach ($config as $key => $value) {
            $handling_fee = self::instance()->where(['type' => $key])->column('handling_fee');
            if (count($handling_fee) <= 0) {
                $handling_fee = 0;
            } else {
                $handling_fee = self::instance()->where(['type' => $key])->column('handling_fee')[0];
            }
            $data[$i]['id']           = $key;
            $data[$i]['title']        = $value;
            $data[$i]['handling_fee'] = $handling_fee;
            $i++;
        }
        return $data;
    }


}